﻿using AiXiu.BLL;
using AiXiu.IBLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AiXiu.Web
{
    /// <summary>
    /// 视频点赞
    /// </summary>
    public class VideoLikeHandler : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            //接受参数
            string videoId = context.Request.QueryString["videoId"];
            string userIdStr = context.Request.QueryString["userId"];
            //判断参数是否为空值
            if (!string.IsNullOrWhiteSpace(videoId) && !string.IsNullOrWhiteSpace(userIdStr))
            {
                int userId = int.Parse(userIdStr);//string类型的userIdStr转换为int类型赋值给userId
                //判断是否点赞
                IUserManager userManager = new UserManager();
                if (userManager.IsLike(videoId, userId))
                {
                    userManager.RemoveLike(videoId, userId);
                }
                else
                {
                    userManager.AddLike(videoId, userId);
                }
            }
            //输出结果
            context.Response.ContentType = "text/plain";
            context.Response.Write("ok");
            context.Response.End();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}